Skip to content

MSSQL: prevent statement-starting keywords from being consumed as implicit aliases#2233

Merged
yoavcloud merged 1 commit intoapache:mainfrom
yoabot-droid:mssql-implicit-alias-disambiguation
Feb 26, 2026
Merged

MSSQL: prevent statement-starting keywords from being consumed as implicit aliases#2233
yoavcloud merged 1 commit intoapache:mainfrom
yoabot-droid:mssql-implicit-alias-disambiguation

Conversation

@yoabot-droid
Copy link
Contributor

Problem

In T-SQL multi-statement scripts delimited by newlines, the parser was consuming statement-starting keywords (DECLARE, EXEC/EXECUTE, INSERT, UPDATE, DELETE, DROP, CREATE, ALTER, TRUNCATE, PRINT, WHILE, RETURN, THROW, RAISERROR, MERGE) as implicit aliases for the preceding SELECT item or table reference, then failing on the next token.

Fix

Extended is_select_item_alias() and is_table_factor_alias() in MsSqlDialect to return false for all of these keywords, matching the existing treatment of IF and ELSE.

Test

Adds test_tsql_statement_keywords_not_implicit_aliases covering column and table alias cases across the full affected keyword set.

…licit aliases

In T-SQL multi-statement scripts delimited by newlines, the parser was
incorrectly consuming statement-starting keywords (DECLARE, EXEC/EXECUTE,
INSERT, UPDATE, DELETE, DROP, CREATE, ALTER, TRUNCATE, PRINT, WHILE,
RETURN, THROW, RAISERROR, MERGE) as implicit aliases for the preceding
SELECT item or table reference, then failing on the next token.

Extended is_select_item_alias() and is_table_factor_alias() in MsSqlDialect
to return false for all of these keywords, matching the existing treatment
of IF and ELSE.

Adds test_tsql_statement_keywords_not_implicit_aliases covering both column
and table alias cases across the affected keyword set.
@yoavcloud yoavcloud added this pull request to the merge queue Feb 26, 2026
Merged via the queue into apache:main with commit bd7f70e Feb 26, 2026
10 checks passed
LucaCappelletti94 pushed a commit to LucaCappelletti94/sqlparser-rs that referenced this pull request Feb 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants